/**
 * 
 */
package com.designpattern.design.factory.absfactory.order;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.designpattern.design.factory.absfactory.Pizza;
import com.designpattern.design.factory.absfactory.factory.PizzaFactory;

/**
 * @author zhangyang
 *
 */
public class PizzaOrder {

	private PizzaFactory factory;

	public PizzaOrder(PizzaFactory pizzaFactory) {
		this.factory = pizzaFactory;
	}

	public void CreatePizza() {
		String orderType;
		do {
			orderType = getType();
			Pizza pizza = factory.createPizza(orderType);
			if (pizza == null) {
				break;
			}
			pizza.prepare();
			pizza.bake();
			pizza.cut();
			pizza.box();
		} while (true);
	}

	// 写一个方法，可以获取客户希望订购的披萨种类
	private String getType() {
		try {
			BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("input pizza 种类:");
			String str = strin.readLine();
			return str;
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}

	public void setFactory(PizzaFactory pizzaFactory) {
		this.factory = pizzaFactory;

	}

}
